package object.obj2D.graphics;

import javax.microedition.khronos.opengles.GL10;

import system.Graphics;

public class Char {
	//------------------------------------------------------------
	/// declare variable
	//------------------------------------------------------------
	private float	m_fSizeWidth = 10;
	private float m_fSizeHeight = 10;
	private Square	m_TextBg;
	private AnimSystem	m_font;
	private int m_textColor;
	private String m_fontName = "/res/raw/fontdata.bin";
	public final int CHAR_SPACE = 0;
	public final int CHAR_0	= CHAR_SPACE + 1;
	public final int CHAR_1 = CHAR_0 + 1;
	public final int CHAR_2 = CHAR_1 + 1;
	public final int CHAR_3 = CHAR_2 + 1;
	public final int CHAR_4 = CHAR_3 + 1;
	public final int CHAR_5 = CHAR_4 + 1;
	public final int CHAR_6 = CHAR_5 + 1;
	public final int CHAR_7 = CHAR_6 + 1;
	public final int CHAR_8 = CHAR_7 + 1;
	public final int CHAR_9 = CHAR_8 + 1;
	public final int CHAR_A = CHAR_9 + 1;
	public final int CHAR_B = CHAR_A + 1;
	public final int CHAR_C = CHAR_B + 1;
	public final int CHAR_D = CHAR_C + 1;
	public final int CHAR_E = CHAR_D + 1;
	public final int CHAR_F = CHAR_E + 1;
	public final int CHAR_G = CHAR_F + 1;
	public final int CHAR_H = CHAR_G + 1;
	public final int CHAR_I = CHAR_H + 1;
	public final int CHAR_J = CHAR_I + 1;
	public final int CHAR_K = CHAR_J + 1;
	public final int CHAR_L = CHAR_K + 1;
	public final int CHAR_M = CHAR_L + 1;
	public final int CHAR_N = CHAR_M + 1;
	public final int CHAR_O = CHAR_N + 1;
	public final int CHAR_P = CHAR_O + 1;
	public final int CHAR_Q = CHAR_P + 1;
	public final int CHAR_R = CHAR_Q + 1;
	public final int CHAR_S = CHAR_R + 1;
	public final int CHAR_T = CHAR_S + 1;
	public final int CHAR_U = CHAR_T + 1;
	public final int CHAR_V = CHAR_U + 1;
	public final int CHAR_W = CHAR_V + 1;
	public final int CHAR_X = CHAR_W + 1;
	public final int CHAR_Y = CHAR_X + 1;
	public final int CHAR_Z = CHAR_Y + 1;
	
	private GL10 gl = Graphics.GetGraphics();
	//------------------------------------------------------------
	/// constructor
	//------------------------------------------------------------
	public Char(){
		this.Init();
	}
	public void Init(){
		m_TextBg = new Square(m_fSizeWidth, m_fSizeHeight);
		m_font = new AnimSystem(m_fontName, 0);
		m_textColor = 0xFFF0F0F0;
		this.setColor(m_textColor);
	}
	//------------------------------------------------------------
	/// render
	//------------------------------------------------------------
	public void Render(char c){
		int iChar = CHAR_SPACE;
		if(c >= '0' && c <= '9'){
			iChar = c - '0' + CHAR_0;
		}
		else if(c >= 'a' && c <= 'z'){
			iChar = c - 'a' + CHAR_A;
		}
		else if(c>= 'A' && c <= 'Z'){
			iChar = c - 'A' + CHAR_A;
		}
		m_font.playFrame(iChar);
		m_TextBg.Render();
	}
	public void DrawString(String str, float x, float y){
		gl.glPushMatrix();
		gl.glLoadIdentity();
		gl.glTranslatef(x, y, 0);
		for(int i = 0; i < str.length(); i++){
			char c = str.charAt(i);
			gl.glTranslatef(m_fSizeWidth, 0, 0);
			this.Render(c);
		}
		gl.glPopMatrix();
	}
	//------------------------------------------------------------
	/// Set attribute
	//------------------------------------------------------------
	public void setiSize(float fSizeWidth, float fSizeHeight) {
		this.m_fSizeWidth = fSizeWidth;
		this.m_fSizeHeight = fSizeHeight;
		this.Init();
	}
	public float getSizeWidth(){
		return this.m_fSizeWidth;
	}
	public float getSizeHeight(){
		return this.m_fSizeHeight;
	}
	public void setColor(int m_textColor) {
		this.m_textColor = m_textColor;
		m_font.setSrcColor(m_font.COLOR_ALL);
		m_font.setDestColor(this.m_textColor);
		m_font.setConvertColor(true);
	}
	public int getColor() {
		return m_textColor;
	}
	//------------------------------------------------------------
	/// getter and setter function
	//------------------------------------------------------------
	public void setFontName(String m_fontName) {
		this.m_fontName = m_fontName;
	}
	public String getFontName() {
		return m_fontName;
	}

	
}
